package sss;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author VernHe
 * @date 2021年08月11日 21:13
 */
public class Day_01_1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int L = in.nextInt();
        int M = in.nextInt();
        System.out.println(L + "---" + M + "---");
        int[][] regions = new int[M][2];
        for (int i = 0; i < M; i++) {
            regions[i][0] = in.nextInt();
            regions[i][1] = in.nextInt();
        }
        Arrays.sort(regions, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] == o2[0] ? o2[0] - o1[0] : o1[0] - o2[0];
            }
        });
        System.out.println(solution(L, M, regions));
    }

    /**
     * @param length    区域总长度
     * @param num       区域数量
     * @param regions   所有区域
     * @return          剩余的数
     */
    private static int solution(int length, int num,int[][] regions) {
        int result = length + 1;
        int l = regions[0][0];
        int r = regions[0][1];
        for (int i = 1; i < num; i++) {
            if (r > regions[i][0]) {
                // 发生重合
                r = regions[i][1] > r ? regions[i][1] : r;
            } else {
                // 不重合
                System.out.println("r : " + r + " ,l" + l);
                result -= r - l + 1;
                // 更新r l
                l = regions[i][0];
                r = regions[i][1];
            }
        }
        return (result -= r - l + 1);
    }

    private static int solution01(int length, int num,int[][] regions) {
        int result = length + 1;
        int r = 0, l = 0;
        for (int i = 0; i < num; i++) {
            l = regions[i][0];
            r = regions[i][1];
            // 后面还有其他区域并且有重合
            while (i <= num - 2) {
                // 重合了
                if (r >= regions[i + 1][0]) {
                    if (r < regions[i + 1][1]) {
                        // 更新r
                        r = regions[++i][1];
                    } else {
                        // 不更新r
                        i++;
                    }
                } else {
                    break;
                }
            }
            /**
             * [   ]
             *  [    ]
             *   []
             *       []
             */
            result -= r - l + 1;
        }
        return result;
    }
}
